package com.example.xjtuse_pc.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by XJTUSE-PC on 2016/3/19.
 */
public class Md5 {
    public String pwd(String password)  {



        StringBuffer buffer;
        try {
            MessageDigest  digest = MessageDigest.getInstance("md5");
         buffer=new StringBuffer();
        byte [] result=digest.digest(password.getBytes());
        //把每个byte与0xff与运算
        for(byte b:result){
            int n=b & 0xff;
            String str=Integer.toHexString(n);
            if(str.length()==1){
                buffer.append("0");
            }
            buffer.append(str);
        }

            return buffer.toString();
    }
    catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";

    }

}
